<template>
  <div>
    <el-form :model="optionForm" @submit.native.prevent="createOption">
      <el-form-item label="选项内容">
        <el-input v-model="optionForm.text"></el-input>
      </el-form-item>
      <el-button type="primary" @click="createOption">创建选项</el-button>
    </el-form>
  </div>
</template>
  
  <script>
  import axios from 'axios';
  import request from '../../utils/request';

  export default {
    props: ['questionId'],
    data() {
      return {
        optionForm: {
            questionId:this.questionId,
            text: '',
        }
      };
    },
    methods: {
      async createOption() {
        try {
          const response = await request.post('api/option/create', null,{params:{
            questionId:this.questionId,
            text:this.optionForm.text,
          }});
          if(response.data==="200"){
          console.log('选项创建成功:', response.data);
          const newOption = {
            id: response.data.id,
            text: response.data.text,
            checked: response.data.checked,
            questionId: this.questionId,
          };
          this.$emit('option-created', newOption);
          this.optionForm.text ='';
          this.optionForm.content='';
        }
        } catch (error) {
          console.error('创建选项失败:', error);
        }
      }
    }
  };
  </script>
  
  <style scoped>
  /* 样式可根据需要调整 */
  </style>
  